/* Copyright (c) 2010-2020 Vadim Surov.
 */
package com.srv.shared;

import java.io.Serializable;

/**
 * Encapsulates a response for {@link Service#login()}.
 */
public class LoginInfo implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7920098483648391150L;


	private boolean loggedIn;

	/**
	 * The nickname.
	 */
	private String nickname;

	/**
	 * The email address.
	 */
	private String email;

	private String baseUrl;	

	private String logoutUrl;

	public LoginInfo() {

	}

	public LoginInfo(boolean loggedIn, String nickname, String email, 
			String baseUrl, String logoutUrl) {
		setLoggedIn(loggedIn);
		setNickname(nickname);
		setEmail(email);
		setBaseUrl(baseUrl);
		setLogoutUrl(logoutUrl);
	}

	public boolean isLoggedIn() {
		return loggedIn;
	}

	public void setLoggedIn(boolean loggedIn) {
		this.loggedIn = loggedIn;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getBaseUrl() {
		return baseUrl;
	}

	public void setBaseUrl(String baseUrl) {
		this.baseUrl = baseUrl;
	}

	public String getLogoutUrl() {
		return logoutUrl;
	}

	public void setLogoutUrl(String logoutUrl) {
		this.logoutUrl = logoutUrl;
	}

	/**
	 * Returns a shorter name for an author. For names of the form a@company.com,
	 * this returns "a". For names of the form First Last, this returns "First".
	 *
	 * @return
	 */
	public String getShortName(String name) {
		final int atIndex = name.indexOf('@');
		if (atIndex > 0) {
			return name.substring(0, atIndex);
		}

		final int spIndex = name.indexOf(' ');
		if (spIndex > 0) {
			return name.substring(0, spIndex);
		}

		return name;
	}
}
